package com.lft.com.oilgas.controller;


import com.lft.com.oilgas.entity.User;
import com.lft.com.oilgas.service.impl.UserServiceImpl;
import com.lft.com.oilgas.util.Result;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author tyqw
 * @since 2024-09-10
 */
@RestController
@RequestMapping("/util/user")
public class  UserController {
     @Autowired
     UserServiceImpl userService;

     //注册
    @RequestMapping("/UserZhuCe")
     public Result ZhuCe(@RequestBody User user){
        int i = userService.insertUser(user);
        return new Result(true,i);
    }

    //登录
    @Transactional
    @RequestMapping("/SelectUser")
    public  Result Denglu(@RequestBody User user){
        User user1 = userService.selectUser(user);
        if(user1==null){
            return  new Result(false,user1);
        }
            return  new Result(true,user1);
    }

    //修改
    @RequestMapping("/UpdataUser")
    public  Result xiugai(@RequestBody User user){
        int i = userService.updateUser(user);
        return  new Result(true,i);

    }

    //查询用户的账号
    @RequestMapping("/userxq/{id}")
    public  Result selectByid(@PathVariable("id") Integer id){
        User user = userService.selsectByid(id);
        return new Result(true,user);
    }
}
